package com.googlecode.gwtdb.client;

import com.google.gwt.core.client.EntryPoint;

import com.googlecode.gwtdb.client.example.Person;
import com.googlecode.gwtdb.client.example.PersonStorage;
import com.googlecode.gwtdb.client.indexeddb.IDBCallback;
import com.googlecode.gwtdb.client.indexeddb.IDBFactory;
import com.googlecode.gwtdb.client.indexeddb.IDBReadyState;
import com.googlecode.gwtdb.client.indexeddb.event.IDBBaseError;
import com.googlecode.gwtdb.client.indexeddb.sub.IDBOpenDBRequest;
import com.googlecode.gwtdb.client.work.IndexedDB;

import java.util.List;
import java.util.logging.Logger;

public class ExampleEntryPoint implements EntryPoint {

  private static Logger logger = Logger.getLogger(ExampleEntryPoint.class.getName());

  
  public static void log(String s) {
    System.out.println(s);
  }

  @Override
  public void onModuleLoad() {
    PersonStorage personStorage = null;
    
    
    
    
    
    IDBFactory idbFactory = IndexedDB.getIndexedDB();

    final IDBOpenDBRequest idbOpenDBRequest = idbFactory.open("asdf", 1);
    
    IDBReadyState readyState = idbOpenDBRequest.getReadyState();
    log("state: " + readyState);

    idbOpenDBRequest.setOnSuccess(new IDBCallback<IDBOpenDBRequest>() {

      @Override
      public void onCallback(IDBOpenDBRequest t) {
        log("open");

        IDBReadyState readyState = t.getReadyState();
        log("state: " + readyState);

      }
    });

    idbOpenDBRequest.setOnError(new IDBCallback<IDBBaseError>() {

      @Override
      public void onCallback(IDBBaseError t) {
        log("error");

      }
    });

    idbOpenDBRequest.setOnBlocked(new IDBCallback<IDBBaseError>() {

      @Override
      public void onCallback(IDBBaseError t) {
        log("blocked");

      }
    });

    idbOpenDBRequest.setOnUpgradeNeded(new IDBCallback<Void>() {

      @Override
      public void onCallback(Void t) {
        log("upgrade");

      }
    });

    log("hm?");

    


  }

  protected void render(List<Person> current) {
    // TODO Auto-generated method stub

  }

}
